package com.example.newfragemnt;

/**
 * Created by 青阳 on 2018/11/1.
 */

import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/10/30 0030.
 */

public class MyAdapter extends BaseAdapter{
    //新闻对象集合
    private ArrayList<Data> datas;
    //这个是创建fragment的管理器
    private Context context;

    public MyAdapter(ArrayList<Data> datas, Context context ){
        this.datas=datas;
        this.context=context;
    }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int i) {
        return i;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        //得到我们的list_items.xml的视图
        View listItems= LayoutInflater.from(context).inflate(R.layout.list_items,viewGroup,false);

        //得到TextView
        TextView item=listItems.findViewById(R.id.txt_item_title);

        //往TextView里面设置值
        //将集合中根据下标得到其中的Date对象，在通过新闻对象得到新闻的标题
        //将他设置到TextView中
        item.setText(datas.get(i).getNew_title());

        return listItems;
    }
}
